﻿using QLKS10_11.BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QLKS10_11.GUI
{
    public partial class form_QLdatphong : Form
    {
        public form_QLdatphong()
        {
            InitializeComponent();
        }
        private static form_QLdatphong _instance;
        public static form_QLdatphong Instance()
        {
            if (_instance == null)
            {
                _instance = new form_QLdatphong();
            }
            return _instance;
        }
        private void btn_qldatphong_Click(object sender, EventArgs e)
        {
            form_main frm1 = form_main.Instance();
            frm1.Show();
            this.Hide();
        }

        private void form_QLdatphong_FormClosed(object sender, FormClosedEventArgs e)
        {
            form_main frm1 = form_main.Instance();
            frm1.Dispose();
        }
        QLdatphong_BLL qldatphong = new QLdatphong_BLL();
        private void form_QLdatphong_Load(object sender, EventArgs e)
        {
            qldatphong.HienThi(gc_qldatphong, bd_qldatphong);
        }

        private void btn_them_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            gridView1.OptionsBehavior.Editable = true;
            DataRow row = qldatphong.NewRow();
            row["maphieudat"] = "";
            row["tenphong"] = "";
            row["makh"] = 1;
            row["manvlap"] = "";
            row["ngaydat"] = "";
            row["ngaythue"] = "";
            qldatphong.Add(row);
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            if (gridView1.RowCount > 0)
            {
                if (MessageBox.Show("Ban co chat muon xoa phong khong ?", "Xoa phong", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    bd_qldatphong.BindingSource.RemoveCurrent();
                    qldatphong.Save();
                }
            }
            else MessageBox.Show("Dach sach phong rong.");
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            gridView1.OptionsBehavior.Editable = true;
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            bd_qldatphong.BindingSource.MoveNext();
            bindingNavigatorPositionItem.Focus();
            qldatphong.Save();
            MessageBox.Show("Luu thanh cong");
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
